package com.amoscloud;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.TreeSet;

/**
 * @description:
 * @author: HuangJiaxin
 * @create: 2022-05-29 22:07
 **/
public class Test042 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String k = scanner.next();
        scanner.close();

        String[] split = input.split(",");
        TreeSet<Integer> set = new TreeSet<>();
        for (String s : split) {
            if(s.contains("-")){
                String[] split1 = s.split("-");
                set.add(Integer.parseInt(split1[0]));
                set.add(Integer.parseInt(split1[1]));
            }else{
                set.add(Integer.parseInt(s));
            }
        }

        //这里的remove，传入的参数要注意，泛型没作用
        set.remove(Integer.valueOf(k));

        ArrayList<Integer> list = new ArrayList<>(set);

        int first = list.get(0);
        int last = first;
        int cur = 0;

        StringJoiner sj = new StringJoiner(",");
        for (int i = 1; i < list.size(); i++) {
            cur = list.get(i);
            if(cur == last+1){
                last = cur;
            }else{
                sbAppend(sj,first,last);
                first = last = cur;
            }
        }
        System.out.println(sj);


    }

    public static void sbAppend(StringJoiner sj,int first,int last) {
        if(first == last){
            sj.add(String.valueOf(first));
        }else{
            sj.add(first + "-" + last);
        }
    }

}
